/*
 * Proja - project management software
 * Copyright (C) 2012  Oleg Kasian
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */
package org.proja.core.entity;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.proja.core.entity.enumerations.MailAction;
import org.proja.core.entity.enumerations.MailType;

/**
 *
 * @author oleg
 */
@Entity
@Table(name = "MAIL_MESSAGES")
public class MailMessage extends AbstractEntity {

    @Id
    @SequenceGenerator(name = "MailMessageSeq", sequenceName = "MAIL_MESSAGES_SEQ")
    @GeneratedValue(generator = "MailMessageSeq")
    @Column(name = "ID", updatable = false)
    private Long id;

    @Column(name = "ACTION")
    private MailAction action = MailAction.DEFAULT;

    @Column(name = "TYPE")
    private MailType type = MailType.HTML;

    /**
     * Comma separated list of recipients.
     */
    @Column(name = "RECIPIENTS", length = 512)
    private String recipients;

    @Column(name = "SUBMITTER", length = 128)
    private String submitter;

    @Lob
    @Column(name = "BODY", nullable = false)
    private String body;

    @Column(name = "SUBJECT", length = 255, nullable = false)
    private String subject;

    @Temporal(TemporalType.TIME)
    @Column(name = "CREATED_ON", updatable = false)
    private Date createdOn = new Date();

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(final Long id) {
        this.id = id;
    }

    public MailAction getAction() {
        return action;
    }

    public void setAction(final MailAction action) {
        this.action = action;
    }

    public String getRecipients() {
        return recipients;
    }

    public void setRecipients(final String recipients) {
        this.recipients = recipients;
    }

    public String getBody() {
        return body;
    }

    public void setBody(final String body) {
        this.body = body;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(final String subject) {
        this.subject = subject;
    }

    public Date getCreatedOn() {
        return createdOn;
    }

    public void setCreatedOn(final Date createdOn) {
        this.createdOn = createdOn;
    }

    public MailType getType() {
        return type;
    }

    public void setType(final MailType type) {
        this.type = type;
    }

    public String getSubmitter() {
        return submitter;
    }

    public void setSubmitter(final String submitter) {
        this.submitter = submitter;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 13 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final MailMessage other = (MailMessage) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

}
